<template>
    <div class="app-container oneSearchNoFooter">
        <div class="customContainer ">
            <!-- 门店-时间-机台类型-机台名称-搜索 -->
            <dj-search-sttn ref="search" @fetchData="fetchData" @saveStoreList="saveStoreList" categoryId="293">
            </dj-search-sttn>
            <el-table highlight-current-row :data="list" border v-loading.body="listLoading" size="small">
                <el-table-column align="center" prop="store_name" label="门店"></el-table-column>
                <el-table-column align="center" prop="project_type" label="机台名称"></el-table-column>
                <el-table-column align="center" prop="push_coins" label="总收币数"
                    :render-header="(h,obj) => renderHeader(h,obj,'刷卡扣币+扫码上币')"></el-table-column>
                <el-table-column align="center" prop="push_money" label="收币金额"
                    :render-header="(h,obj) => renderHeader(h,obj,'收币金额=机台收币数x当前币值')"></el-table-column>
                <el-table-column align="center" prop="sweep_money" label="扫码支付金额"></el-table-column>
                <el-table-column align="center" prop="times" label="游玩次数"
                    :render-header="(h,obj) => renderHeader(h,obj,'扫码和刷卡游玩的总局')"></el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
    import { getList } from "@/api/storage_control/machine_consume_form";
    import { renderHeader } from '@/utils';
    export default {
        data() {
            return {
                renderHeader,
                listLoading: false,
                list: [],
            };
        },
        methods: {
            // 子组件传过来的选择的门店列表
            saveStoreList(saveStoreList) {
                //console.log(saveStoreList)
                this.list = saveStoreList
            },
            // 列表获取
            fetchData(formInline) {
                this.listLoading = true;
                getList(JSON.parse(JSON.stringify(formInline))).then(response => {
                    response.forEach(function (val, i) {
                        val.push_money = (val.push_money / 1000000).toFixed(2);
                        val.sweep_money = (val.sweep_money / 1000000).toFixed(2);
                        val.times = val.push_count * 1 + val.sweep_count * 1;
                        val.push_coins=val.sweep_coins*1+val.push_coins*1;
                    });
                    if (response.length == 0) {
                        let list = JSON.parse(JSON.stringify(this.list));
                        list.forEach((val, i) => {
                            val.project_type = '-';
                            val.push_coins = '-';
                            val.push_money = '-';
                            val.sweep_money = '-';
                            val.times = '-';
                        })
                        this.list = list
                    } else {
                        this.list = response;
                    }
                    this.listLoading = false;
                }).catch(res=>{
                    this.listLoading=false;
                })
            },
        }
    };
</script>